package com.zhupf.binarySearch;

/**
 * @author zhupf
 * @date 2024年01月18日 17:19
 * @Description 153. 寻找旋转排序数组中的最小值
 */
public class FindMin {

    public static void main(String[] args) {
        int[] nums = {5,1,2,3,4};
        findMin(nums);
    }


    public static int findMin(int[] nums) {
        int left = 0;
        int right = nums.length-1;
        int mid = 0;
        while (left <= right){
            mid = left + (right -left)/2;
            if(nums[mid] < nums[right]){
                if(mid > left && nums[mid] < nums[mid-1]){
                    break;
                }
                right = mid -1;
            }else {
                left = mid +1;
            }
        }
        return nums[mid];
    }
}
